package org.example.Controller;

import org.example.service.IRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.geo.*;
import org.springframework.data.redis.connection.*;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.core.query.SortQuery;
import org.springframework.data.redis.core.query.SortQueryBuilder;
import org.springframework.data.redis.core.types.RedisClientInfo;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * https://mp.weixin.qq.com/s/uZ3HTtdoVKFkZZ5_0akbkg
 * 注意：这里必须集成数据源，不然不会生效
 */
@RestController("/question")
public class QuestionController {

    @Autowired
    private IRedisService redisService;



    /**
     * 错误演示
     * @param key
     * @return
     */
    @RequestMapping("/increaseCounterError")

    public Long increaseCounterError(String key) {
        Long result= redisService.increaseCounterError(key);
        return result;
    }


    /**
     * 测试添加 @Transactional 注解后，Redis 操作是否有问题
     * 悟空聊架构
     */
    @RequestMapping("/test-transaction-annotations")
    public Long testRedisWithTransaction(String key) {
        Long result = redisService.testTransactionAnnotations();
        return result;
    }


    @RequestMapping("/test-redis-multi")
    public Void testRedisMulti(){
        redisService.testRedisMulti();
        return null;
    }





}
